import { axios } from '@/utils/request'
import apiDefine from '@/api/api-define'

export const login = (username, password) => {
  let params = {
    username: username,
    password: password
  }

  return new Promise((resolve, reject) => {
    let mockData = {
      access_token: '111111',
      expires_in: 3600
    }
    resolve(mockData)
  })

  // return axios({
  //   url: apiDefine.login,
  //   method: 'post',
  //   data: params
  // })
}

export const logout = (token) => {
  return axios({
    url: apiDefine.user.logout,
    method: 'post',
    data: {
      token: token
    }
  })
}

export const userInfo = () => {
  return new Promise((resolve, reject) => {
    let mockData = {
      user: {
        id: '666666',
        username: 'xiami',
        nickname: '虾米',
        realName: '陈静远',
        email: '460228593@qq.com',
        avatar: 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1932577929,1314842054&fm=26&gp=0.jpg'
      },
      rules: {}
    }
    resolve(mockData)
  })

  // return axios({
  //   url: apiDefine.user.user_info,
  //   method: 'get'
  // })
}

export const getSmsCaptcha = (mobile) => {
  return new Promise((resolve, reject) => {
    let data = {
      mobile: '13222222222',
      captcha: '666666'
    }
    resolve(data)
  })
}

// FIXME MOCK
export const getPermissionList = () => {
  return new Promise((resolve, reject) => {
    let permissions = {
      page: {
        home: true,
        home_index: true
      },
      component: {
        edit_button: true,
        publish_button: false
      }
    }
    resolve(permissions)
  })

  // return axios({
  //     url: apiConst.user.permission_list,
  //     method: 'get'
  // })
}
